<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>splice</title>
	</head>
	<body>
		<p id="old"></p>
		<p id="new">点击按钮添加和删除元素</p>
		<button onclick="my()">点击</button>
		<script>
			function my(){
				//获取p标签元素对象
				var p=document.getElementById('old');
				var mynew=document.getElementById('new');
				//定义数组
				var fruits=["Banan","Orange","Apple","Mango"];
				old.innerHTML=fruits;
				
				//在orange元素只有，添加元素：pear、peach
				/*fruits.splice(2,0,"pear","peach");
				mynew.innerHTML=fruits;*/
				//在第2个元素之后，删除2个元素
				fruits.splice(1,2);
				mynew.innerHTML=fruits;
			}
		</script>
	</body>
</html>
